package com.bstek.uflo.form.view.common.impl;

import java.util.Map;

import org.htmlparser.nodes.TagNode;
import org.htmlparser.tags.InputTag;
import org.springframework.util.StringUtils;

import com.bstek.dorado.view.View;
import com.bstek.dorado.view.widget.Component;
import com.bstek.dorado.view.widget.form.RadioGroup;
import com.bstek.uflo.form.Constants;
import com.bstek.uflo.form.model.TableDefinition;
import com.bstek.uflo.form.view.common.AbstractComponentBuilder;

/**
 * @author Jacky.gao
 * @since 2013年11月13日
 */
@org.springframework.stereotype.Component("com.bstek.uflo.form.view.common.impl.RadioGroupBuilder")
public class RadioGroupBuilder extends AbstractComponentBuilder {
	public boolean support(TagNode node) {
		if(node instanceof InputTag){
			InputTag input=(InputTag)node;
			String css=input.getAttribute("class");
			if(css!=null && css.equals("ufloradio")){
				return true;
			}
		}
		return false;
	}

	public void build(TagNode node, View view, Map<String, Component> map,Map<String,Boolean> mappingMap,TableDefinition table) {
		InputTag input=(InputTag)node;
		String id=input.getAttribute("id");
		if(map.containsKey(id))return;
		String field=input.getAttribute("bindingfield");
		if(StringUtils.isEmpty(field))return;
		RadioGroup radioGroup=new RadioGroup();
		radioGroup.setRenderOn("#"+id);
		radioGroup.setDataSet(Constants.DATASET);
		radioGroup.setProperty(field.toLowerCase());
		view.addChild(radioGroup);
		map.put(id, radioGroup);
	}

}
